package com.zhongge.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zhongge.entity.Teacher;
import com.zhongge.mapper.TeacherMapper;
import com.zhongge.service.ITeacherService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zhongge
 * @since 2025-11-09
 */
@Service
public class TeacherServiceImpl extends ServiceImpl<TeacherMapper, Teacher> implements ITeacherService {

    @Override
    public Teacher login(String jobNumber, String password) {
        //首先创建查询条件对象
        QueryWrapper<Teacher> teacherQueryWrapper = new QueryWrapper<>();
        teacherQueryWrapper.eq("job_number",jobNumber)
                .eq("password",password);
        //查询
        return this.getOne(teacherQueryWrapper);
    }


    @Override
    public boolean changePassword(Long teacherId, String oldPassword, String newPassword) {
        //首先看一下 旧密码是否存在
        //如果旧密码不存在的话 此时就修改失败了
        Teacher byId = this.getById(teacherId);
        if (byId == null || !byId.getPassword().equals(oldPassword)){
            return false;
        }
        //到这里就可以修改密码
        byId.setPassword(newPassword);
        return this.updateById(byId);
    }
}
